package com.hz.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JWTUtil {
    private static String name="ithema";
    private static Long time=43200000L;


    //生成jwt令牌
    public static String generateJWT(Map<String,Object> map)
        {
            String jwt = Jwts.builder()
                    .signWith(SignatureAlgorithm.HS256, name)
                    .setClaims(map)
                    .setExpiration(new Date(System.currentTimeMillis()+time))
                    .compact();
            return jwt;
        }
    public static Claims parseJwt(String jwt){
        Claims claim = Jwts.parser()
                .setSigningKey(name)
                .parseClaimsJws(jwt)
                .getBody();
        return claim;
    }
}

